(function(){
	function $(){
		alert("buffering!");
	}
	window['cjl'] = {}; //把CJL 命名空间加到window
	/*
	function $() {
		var elements = new Array();
		for(var i = 0; i < arguments.length; i++) {
			var element = arguments[i];
			if(typeof element == 'string') {
				element = document.getElementById(element);
			}
			
			elements.push(element);
		}
		return elements;
	}
	window['CJL']['$'] = $; //把$函数加到CJL
	*/
	
	function post(url,params,callback){
		//alert("Cjl.post");
		var url = arguments[0];
		var params = arguments[1];
		var callback = arguments[2];
		Zepto.post(url,params, function(json){
			var obj;
			if(typeof(json) == 'string') {
				obj = JSON.parse(json);
			} else {
				obj = json;
			}
			
			if(obj.code == 401){
				document.location = "/mobile/login.html";	
			}else if(obj.code == 0){
				callback(obj.body);
			}else{
				alert(obj.msg);
			}
		});
	}
	window['cjl']['post'] = post; //把get函数加到CJL
	
	function get(url, params, callback){
		//alert("Cjl.get");
		var url = arguments[0];
		var params = arguments[1];
		var callback = arguments[2];
		Zepto.get(url, params, function(json){
			var obj;
			if(typeof(json) == 'string') {
				obj = JSON.parse(json);
			} else {
				obj = json;
			}
			if(obj.code == 401){
				document.location = "/mobile/login.html";	
			} else if(obj.code == 0) {
				callback(obj.body);
			} else {
				alert(obj.msg);
			}
		});
	}
	window['cjl']['get'] = get; //把get函数加到CJL
	
	function requestData(){
		//alert("Cjl.requestData is called");
		var name = arguments[0];
		var strHref = window.location.href;
		var pos = strHref.indexOf("?");
		var strRight = strHref.substr(pos + 1);
		var arrayTmp = strRight.split("&");
		for(var i=0;i<arrayTmp.length;i++){
			var tmp = arrayTmp[i].split("=");
			if(tmp[0]==name){
				return tmp[1];
			}
		}
	}
	window['cjl']['requestData'] = requestData; //把$函数加到CJL
	
	function getTitle() {
		//alert("Cjl.getTitle is called");
		var url = "/common/title";
		get(url, {}, function(body) {
			var title = body;
			Zepto("title").text(title);
		});
	}
	window['cjl']['getTitle'] = getTitle; //把$函数加到CJL
	
	function setPageCommon() {
		//alert("Cjl.setPageCommon is called");
		var random = Math.random();
		Zepto(".footerWrap").html('<iframe src="/mobile/footer.html?s='+random+'" style="padding: 0;margin: 0;width: 100%;height: 100%;" width="100%" height="100%" scrolling="no" frameborder="0"></iframe>');
		Zepto(".bottomWrap").html('<iframe src="/mobile/bottom.html?s='+random+'" style="padding: 0;margin: 0;width: 100%;height: 100%;" width="100%" height="100%" scrolling="no" frameborder="0"></iframe>');
	}
	window['cjl']['setPageCommon'] = setPageCommon; //把$函数加到CJL
})();